// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.assets.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.assets.controller.request.QueryAssetsExpenseBudgetReq;
import com.liuxinlong.modules.assets.controller.request.UpdateExpenseBudgetReq;
import com.liuxinlong.modules.assets.service.AssetsExpenseBudgetService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.ExpenseBudget;
import com.liuxinlong.modules.entity.ExpenseYearBudget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 实验费预算管理控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2024-01-11
 */
@RestController
@RequestMapping("/assets/expense-budget")
public class AssetsExpenseBudgetController {
    @Autowired
    private AssetsExpenseBudgetService assetsExpenseBudgetService;

    /**
     * 分页查询实验费预算管理信息列表
     *
     * @param req 请求信息
     * @return 实验费预算管理信息列表
     */
    @PostMapping("page")
    public BaseResp pageExpenseBudgetList(@RequestBody QueryAssetsExpenseBudgetReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("year", req.getYear());
        queryMap.put("domain", req.getDomain());
        List<Map<String, Object>> dataList = assetsExpenseBudgetService.pageExpenseBudgetInfo(queryMap);
        int totalNum = assetsExpenseBudgetService.getExpenseBudgetInfoCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询实验费预算信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 新增实验费预算信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增实验费预算信息", business = LogBusinessConstants.ASSETS_EXPENSE_MANAGEMENT, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addExpenseBudgetInfo(@RequestBody UpdateExpenseBudgetReq req) {
        ExpenseBudget expenseBudget = new ExpenseBudget();
        expenseBudget.setDomain(req.getDomain());
        expenseBudget.setYear(req.getYear());
        expenseBudget.setAmount(req.getAmount());
        expenseBudget.setDepartment(req.getDepartment());
        expenseBudget.setRemark(req.getRemark());
        assetsExpenseBudgetService.addExpenseBudgetInfo(expenseBudget);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增实验费预算信息成功");
        return resp;
    }

    /**
     * 修改实验费预算信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "修改实验费预算信息", business = LogBusinessConstants.ASSETS_EXPENSE_MANAGEMENT, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateExpenseBudgetInfo(@RequestBody UpdateExpenseBudgetReq req) {
        ExpenseBudget expenseBudget = new ExpenseBudget();
        expenseBudget.setId(req.getId());
        expenseBudget.setDomain(req.getDomain());
        expenseBudget.setYear(req.getYear());
        expenseBudget.setAmount(req.getAmount());
        expenseBudget.setDepartment(req.getDepartment());
        expenseBudget.setRemark(req.getRemark());
        assetsExpenseBudgetService.updateExpenseBudgetInfo(expenseBudget);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改实验费预算信息成功");
        return resp;
    }

    /**
     * 删除实验费预算信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除实验费预算信息", business = LogBusinessConstants.ASSETS_EXPENSE_MANAGEMENT, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteExpenseBudgetInfo(@RequestBody BaseDeleteReq req) {
        assetsExpenseBudgetService.deleteExpenseBudgetInfo(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除实验费预算信息成功");
        return resp;
    }

    /**
     * 分页查询实验费年度预算管理信息列表
     *
     * @param req 请求信息
     * @return 实验费年度预算管理信息列表
     */
    @PostMapping("year-page")
    public BaseResp pageExpenseYearBudgetList(@RequestBody QueryAssetsExpenseBudgetReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("year", req.getYear());
        queryMap.put("domain", req.getDomain());
        List<Map<String, Object>> dataList = assetsExpenseBudgetService.pageExpenseYearBudgetInfo(queryMap);
        int totalNum = assetsExpenseBudgetService.getExpenseYearBudgetInfoCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询实验费年度预算信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 新增实验费预算信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("year-add")
    @LogAnnotation(value = "新增实验费年度预算信息", business = LogBusinessConstants.ASSETS_EXPENSE_MANAGEMENT, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addExpenseYearBudgetInfo(@RequestBody UpdateExpenseBudgetReq req) {
        ExpenseYearBudget yearBudget = new ExpenseYearBudget();
        yearBudget.setDomain(req.getDomain());
        yearBudget.setYear(req.getYear());
        yearBudget.setAmount(req.getAmount());
        assetsExpenseBudgetService.addExpenseYearBudgetInfo(yearBudget);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增实验费年度预算信息成功");
        return resp;
    }

    /**
     * 修改实验费预算信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("year-update")
    @LogAnnotation(value = "修改实验费年度预算信息", business = LogBusinessConstants.ASSETS_EXPENSE_MANAGEMENT, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateExpenseYearBudgetInfo(@RequestBody UpdateExpenseBudgetReq req) {
        ExpenseYearBudget yearBudget = new ExpenseYearBudget();
        yearBudget.setId(req.getId());
        yearBudget.setDomain(req.getDomain());
        yearBudget.setYear(req.getYear());
        yearBudget.setAmount(req.getAmount());
        assetsExpenseBudgetService.updateExpenseYearBudgetInfo(yearBudget);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改实验费年度预算信息成功");
        return resp;
    }

    /**
     * 删除实验费预算信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("year-delete")
    @LogAnnotation(value = "删除实验费预算信息", business = LogBusinessConstants.ASSETS_EXPENSE_MANAGEMENT, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteExpenseYearBudgetInfo(@RequestBody BaseDeleteReq req) {
        assetsExpenseBudgetService.deleteExpenseYearBudgetInfo(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除实验费预算信息成功");
        return resp;
    }
    
}
